package dbPhase.hypeerweb;
/**
 * DownPointerRole extends Connection and overrides all the methods to change the connections
 * in reference as a downpointer.
 *
 * @see Connection
 *
 *
 * @author scott44
 *
 */
public class DownPointerRole extends Connection {
	public DownPointerRole(Node n, Node b) {
		super(n, b);
	}

	@Override
	public void addConnection(Node newNode) {
		delegate.downPointers.add(newNode);
		newNode.upPointers.add(delegate);
		delegate.nodeState = DownPointingNodeState.getSingleton();
	}

	@Override
	public void removeConnection(Node remove) {
		delegate.upPointers.remove(remove);
		remove.downPointers.remove(delegate);

		if (delegate.upPointers.size() == 0) {
			delegate.nodeState = StandardNodeState.getSingleton();
		}
	}

	@Override
	public void replaceConnection(Node oldNode, Node newNode) {
		delegate.upPointers.remove(oldNode);
		oldNode.downPointers.remove(delegate);
		delegate.upPointers.add(newNode);
		newNode.downPointers.add(delegate);
	}
}
